function checkInputData(message) {

    var fromtime = document.getElementById('j_id_id5:itxFromTime');
    var fromdate = document.getElementById('j_id_id5:itxFromDate');
    var totime = document.getElementById('j_id_id5:itxToTime');
    var todate = document.getElementById('j_id_id5:itxToDate');
    var invalid = true;
    var wcolor = 'white';
    var ocolor = 'orange';

    fromtime.style.background = wcolor;
    fromdate.style.background = wcolor;
    totime.style.background = wcolor;
    todate.style.background = wcolor;

    switch (true) {
        case (fromtime.value != null && fromtime.value.length != 0 && !checkTime(fromtime.value)):
            fromtime.style.background = ocolor;
            fromtime.focus();
            invalid = false;
            break;
        case (fromdate.value == null || fromdate.value.length == 0 || !checkDate(fromdate.value)):
            fromdate.style.background = ocolor;
            fromdate.focus();
            invalid = false;
            break;
        case (totime.value != null && totime.value.length != 0 && !checkTime(totime.value)):
            totime.style.background = ocolor;
            totime.focus();
            invalid = false;
            break;
        case (todate.value == null || todate.value.length == 0 || !checkDate(todate.value)):
            todate.style.background = ocolor;
            todate.focus();
            invalid = false;
            break;
        default :
            break;
    }

    if (invalid) {
        if (fromdate.value > todate.value) {
            fromdate.style.background = ocolor;
            todate.style.background = ocolor;
            todate.focus();
            invalid = false;
        }
        else if (fromdate.value == todate.value 
                && fromtime.value.length > 0
                && totime.value.length > 0
                && fromtime.value >= totime.value) {
            fromtime.style.background = ocolor;
            totime.style.background = ocolor;
            totime.focus();
            invalid = false;
        }
    }

    if (invalid) {
        invalid = confirm(message);
    }
    return invalid;
}

function checkTime(t) {
    //check format hh:mi e.g. 23:59
    //trim whitespace
    t.replace(/^\s*/, "").replace(/\s*$/, "");
    var patt = /^([0,1][0-9]|2[0-3]):([0-5][0-9])$/g;
    return patt.test(t);
}

function checkDate(t) {
    //check format dd/mm/yyyy e.g. 30/04/2012
    t.replace(/^\s*/, "").replace(/\s*$/, "");
    var patt = /^(0[1-9]|[1,2][0-9]|3[0-1])(\/)(0[1-9]|1[0-2])(\/)([1-3]\d{3})$/g;
    if (patt.test(t) && checkDateInMonth(t)) {
        return true;
    }
    else {
        return false;
    }
}

function checkDateInMonth(mydate) {
    //mydate's format is dd/MM/yyyy
    var arg = mydate.split('/');
    var dd = arg[0] / 1;
    var mm = arg[1] / 1;
    var yyyy = arg[2] / 1;
    var isdate = false;

    switch (true) {
        case (mm == 2):
            if (yyyy % 4 == 0) {
                if (dd >= 1 && dd <= 29) {
                    isdate = true;
                }
            }
            else {
                if (dd >= 1 && dd <= 28) {
                    isdate = true;
                }
            }
            break;
        case (mm == 4 || mm == 6 || mm == 9 || mm == 11):
            if (dd >= 1 && dd <= 30) {
                isdate = true;
            }
            break;

        case (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12):
            if (dd >= 1 && dd <= 31) {
                isdate = true;
            }
            break;

        default :
            isdate = false;
    }
    return isdate;
}